import { useI18n as useVueI18n } from 'vue-i18n'
import type { MessageSchema, SupportedLocale } from '../types/i18n'

/**
 * 类型安全的i18n组合函数
 * 提供完整的TypeScript代码提示
 */
export function useI18n() {
  const { t, locale, availableLocales, ...rest } = useVueI18n<MessageSchema>()

  // 类型安全的翻译函数
  const $t = (key: keyof MessageSchema | string, args?: unknown[]): string => {
    return args ? t(key as string, args) : t(key as string)
  }

  // 类型安全的语言切换
  const changeLocale = (newLocale: SupportedLocale) => {
    locale.value = newLocale as string
  }

  return {
    t: $t,
    locale,
    availableLocales,
    changeLocale,
    ...rest,
  }
}
